package com.ziroom.finance.rabbitmq;

import com.ziroom.finance.rabbitmq.consumer.QueueConsumer;
import com.ziroom.finance.rabbitmq.producer.Producer;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.concurrent.TimeoutException;

public class Main {
    public Main() throws Exception{
        Producer producer = new Producer("queue");

        for (int i = 0; i< 100 ; i++) {
            HashMap message = new HashMap();
            message.put("message number", i);
            producer.sendMessage(message);
            System.out.println("Message Number "+ i +" sent.");
        }
    }

    public static void createConsumer() throws IOException, TimeoutException {
        QueueConsumer consumer = new QueueConsumer("queue");
        Thread consumerThread = new Thread(consumer);
        consumerThread.start();

    }

    /**
     * @param args
     * @throws SQLException
     * @throws IOException
     */
    public static void main(String[] args) throws Exception{
//        new Main();
        createConsumer();
    }
}